package com.datastructure;

class Node{
    public int value ;
    public Node next ;
    public Node(int val,Node next){
        this.value = val ;
        this.next = next ;
    }
}

public class LinkReverse {
    public static void main(String[] args){
        Node dummy  = new Node(0,null);
        Node head = dummy ;
        Node head1 = dummy ;
        for(int i=1;i<10;i++){
            Node node = new Node(i,null);
            head1.next = node ;
            head1 = node ;
        }

        Node result = reverse(dummy.next);
        while(result !=null){
            System.out.print("["+result.value+"] ");
            result = result.next ;
        }
    }

    private static Node reverse(Node node){
        Node pre = null ;
        Node cur = node ;

        while(cur != null){
            Node next = cur.next ;
            cur.next = pre ;

            pre = cur ;
            cur = next ;
        }
        return  pre ;
    }
}
